jQuery(document).on("pageinit", "[data-role='page'][data-pagetype='register']", function() {
    var page = jQuery(this);
    page.find("a.register").click(function(event) {
        var email = page.find("#email");
        var nickname = page.find("#nickname");
        var password = page.find("#password"); 
        $.ajax({
            type: "POST",
            url: URL_ACTION_REGISTER,
            data: {
                email: email.val(),
                nickname: nickname.val(),
                password: password.val(),
            },

            success: function(msg) {
                $.cookie("wia_email", email.val());
                $.cookie("wia_password", password.val());
                $.mobile.changePage(URL_VIEW_SERVICES, {transition: 'slide', reverse: false, changeHash: true });
            },

            error: function(req, status, error) {
                var errmsg = page.find("div.errmsg");
                if (errmsg.length != 0){
                    errmsg.find("p").html("用户注册失败！");
                    errmsg.popup("open");
                }
            }
        });
    });

});
